package sketch.specs;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.Comment;
import org.eclipse.jdt.core.dom.MethodDeclaration;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class SketchedMethodDeclarationTest extends TestCase {
	
	public static Test suite() {
		return new TestSuite(SketchedMethodDeclarationTest.class);
	}
	
	public void testSketchedChooseOneBlock() {
		System.out.println("Testing sketched choosing one block?");
		String filePath = "./testfiles/sketch/specs/SampleCode.java";;
		SketchedMethodsCreator creator = new SketchedMethodsCreator(filePath);
		Map<Comment, SketchedBlock> sketchedBlocks = creator.getSketchedBlocks();
		System.out.println(sketchedBlocks.size());
		assertTrue(sketchedBlocks.size() == 10);
		
		Collection<SketchedBlock> blockList = sketchedBlocks.values();
		for(SketchedBlock block : blockList) {
			if(block instanceof SketchedChooseOneBlock) {
				System.out.println(" -------- processing choose one block -------- ");
				List<Block> replicated = block.replicate();
				for(Block b : replicated) {
					System.out.println(b);
					System.out.println("++++++");
				}
				System.out.println("\n");
			}
		}
		System.out.println("\n\n\n");
	}
	
	public void testSketchedAllBlock() {
		System.out.println("Testing sketched choosing all block?");
//		String filePath = "./tests/sketch/specs/samplecode.txt";;
		String filePath = "./testfiles/sketch/specs/SampleCode.java";;

		SketchedMethodsCreator creator = new SketchedMethodsCreator(filePath);
		Map<Comment, SketchedBlock> sketchedBlocks = creator.getSketchedBlocks();
		System.out.println(sketchedBlocks.size());
		assertTrue(sketchedBlocks.size() == 10);
		
		Collection<SketchedBlock> blockList = sketchedBlocks.values();
		for(SketchedBlock block : blockList) {
			if(block instanceof SketchedChooseAllBlock) {
				System.out.println(" -------- processing choose all block -------- ");
				List<Block> replicated = block.replicate();
				for(Block b : replicated) {
					System.out.println(b);
					System.out.println("++++++");
				}
				System.out.println("\n");
			}
		}
		System.out.println("\n\n\n");
	}
	
	public void testSketchedRepeatBlock() {
		System.out.println("Testing sketched choosing all block?");
//		String filePath = "./tests/sketch/specs/samplecode.txt";;
		String filePath = "./testfiles/sketch/specs/SampleCode.java";;
		SketchedMethodsCreator creator = new SketchedMethodsCreator(filePath);
		Map<Comment, SketchedBlock> sketchedBlocks = creator.getSketchedBlocks();
		System.out.println(sketchedBlocks.size());
		assertTrue(sketchedBlocks.size() == 10);
		
		Collection<SketchedBlock> blockList = sketchedBlocks.values();
		for(SketchedBlock block : blockList) {
			if(block instanceof SketchedRepeatBlock) {
				System.out.println(" -------- processing repeat block -------- ");
				List<Block> replicated = block.replicate();
				for(Block b : replicated) {
					System.out.println(b);
					System.out.println("++++++");
				}
				System.out.println("\n");
			}
		}
		System.out.println("\n\n\n");
	}
	
	public void testMethodExpansion() {
		System.out.println("\n\n executing testMethodExpansion ----\n\n");
//		String filePath = "./tests/sketch/specs/samplecode.txt";;
		String filePath = "./testfiles/sketch/specs/SampleCode.java";;
		SketchedMethodsCreator creator = new SketchedMethodsCreator(filePath);
		List<SketchedMethodDeclaration> sketchedMethods = creator.createSketchedMethodList();
		
		assertTrue(sketchedMethods.size() == 7);
		
		for(SketchedMethodDeclaration sketchedMethod : sketchedMethods) {
			List<MethodDeclaration> methods = sketchedMethod.getMethodsAfterExpansion();
			//see how many methods
			System.out.println("++: " + methods.size());
			for(MethodDeclaration m : methods) {
				System.out.println(m);
			}
			//break;
		}
	}
}